﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ELab.Serialization.Data;
using ELab.Communication.Messages.ControllerMessages;

namespace ELab.Controls
{
    public partial class ListStudentControl : UserControl
    {
        public ListStudentControl()
        {
            InitializeComponent();
        }
        private List<StudentControl> studentsControl = new List<StudentControl>();
        public event EventHandler OnItemAnswer;
        public event EventHandler OnItemLogout;
        public event EventHandler OnItemChangePass;
        private User[] _Users = null;
        public User[] Users
        {
            get { return _Users; }
            set
            {
                _Users = value;
                if (_Users != null)
                {
                    this.Controls.Clear();
                    foreach (User user in _Users)
                    {
                        StudentControl infor = new StudentControl { CurrentUser = user, Name = user.ApplicationName };
                        infor.OnUserLogout += infor_UserLogout;
                        infor.OnUserAnswer += infor_UserAnswer;
                        infor.OnUserChangePass += infor_ChangePass;
                        infor.Dock = DockStyle.Top;
                        this.Controls.Add(infor);
                        studentsControl.Add(infor);
                    }
                }

            }
        }

        public void UpdateButtonState(bool status)
        {
            foreach (var item in studentsControl)
            {
                item.UpdateButtonState(status);
            }
        }

        private void infor_UserLogout(object sender, EventArgs e)
        {
            if (OnItemLogout != null) OnItemLogout(sender, e);
        }

        private void infor_UserAnswer(object sender, EventArgs e)
        {
            if (OnItemAnswer != null) OnItemAnswer(sender, e);
        }

        private void infor_ChangePass(object sender, EventArgs e)
        {
            if (OnItemChangePass != null) OnItemChangePass(sender, e);
        }
    }
}
